package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.activity.ActivityDTO;
import com.qk.entity.Activity;
import com.qk.management.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 * @author sch
 * @version 1.0
 * @since 2025-10-09-14:48
 */
@Slf4j
@RestController
@RequestMapping("/activities")
public class ActivityController {
    @Autowired
    private ActivityService activityService;

    @GetMapping
    public Result listActivity(ActivityDTO activityDTO) {
        log.info("查询活动列表: {}", activityDTO);
        PageResult <Activity> pageResult= activityService.listActivity(activityDTO);
        return Result.success(pageResult);
    }

    @DeleteMapping("/{id}")
    public Result deleteActivity(@PathVariable Integer id) {
        log.info("删除活动: id={}", id);
        activityService.deleteActivity(id);
        return Result.success();
    }

    @PostMapping
    public Result addActivity(@RequestBody Activity activity) {
        log.info("添加活动: {}", activity);
        activityService.addActivity(activity);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getActivityById(@PathVariable Integer id) {
        log.info("查询活动: id={}", id);
        Activity activity = activityService.getActivityById(id);
        return Result.success(activity);
    }

    @PutMapping
    public Result updateActivity(@RequestBody Activity activity) {
        log.info("修改活动: {}", activity);
        activityService.updateActivity(activity);
        return Result.success();
    }

    @GetMapping("/type/{type}")
    public Result listActivitiesByType(@PathVariable Integer type) {
        log.info("根据类型查询活动: type={}", type);
        List<Activity> activities = activityService.listActivitiesByType(type);
        return Result.success(activities);
    }
}
